'use strict';
/* blog_category Controllers */
define( function(){
	
	var BlogCategoryCtrl = ['$scope', '$http', function($scope, $http){
		//获取博客类别 
		$http({	method:'post',
			url:"blog_category/findListByUid",
			params:$scope.blog_category
		}).success(function(result){
			$scope.blog_categorys = result.datas;
			
		}).error(function(){
			alert("网络连接失败");
		});
		
		$scope.blog_category = {};
		
		$scope.add = function(){
			if(!$scope.blog_category.name){
				alert("请填写类别名称");return;
			}
			$http({	method:'post',
				url:"blog_category/addOrUpdate",
				params:$scope.blog_category
			}).success(function(result){
				if(result.status == 1){
					$scope.blog_categorys.push(result.blog_category);
				}else{
					alert(result.msg);
				}
				
			}).error(function(){
				alert("网络连接失败");
			});
		};
		
		$scope.del = function(index, blog_cate){
			
			if(!confirm("确定删除此记录")){return;}
			
			$http({	method:'post',
				url:"blog_category/deleteById",
				params:{id:blog_cate.id}
			}).success(function(result){
				if(result.status == 1){
					$scope.blog_categorys.splice(index, 1);
				}else{
					alert(result.msg);
				}
				
			}).error(function(){
				alert("网络连接失败");
			});
		};
	}];
	
	return {"blogCategory": BlogCategoryCtrl};
});